//********************************************************************************************************
// Product Name: MapWindow.dll Alpha
// Description:  The core assembly for the MapWindow 6.0 distribution.
//********************************************************************************************************
// The contents of this file are subject to the Mozilla Public License Version 1.1 (the "License"); 
// you may not use this file except in compliance with the License. You may obtain a copy of the License at 
// http://www.mozilla.org/MPL/ 
//
// Software distributed under the License is distributed on an "AS IS" basis, WITHOUT WARRANTY OF 
// ANY KIND, either expressed or implied. See the License for the specific language governing rights and 
// limitations under the License. 
//
// The Original Code is MapWindow.dll
//
// The Initial Developer of this Original Code is Ted Dunsford. Created 11/19/2009 11:03:57 AM
// 
// Contributor(s): (Open source contributors should list themselves and their modifications here). 
//
//********************************************************************************************************
using System;
using System.Windows.Forms;
using MapWindow.Map;


namespace SkiPathFinder
{
    /// <summary>
    /// MeasureDialog
    /// </summary>
    public class DrawPathDialog : Form
    {
        /// <summary>
        /// Occurs when the measuring mode has been changed.
        /// </summary>
        public event EventHandler MeasureModeChanged;
        private ToolTip ttHelp;
        private Label lblMeasure;
        private Label lblTotalValue;

        private double _distFromMeters = 1;
        
        private ToolStripMenuItem _currentDist;
        
        private double _totalDistance;
        
        private MeasureModes _measureMode;
        
        private Label label1;
        #region Private Variables

        /// <summary>
        /// Required designer variable.
        /// </summary>
        private System.ComponentModel.IContainer components = null;



        #endregion


        #region Windows Form Designer generated code

        /// <summary>
        /// Required method for Designer support - do not modify
        /// the contents of this method with the code editor.
        /// </summary>
        private void InitializeComponent()
        {
            this.components = new System.ComponentModel.Container();
            System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(DrawPathDialog));
            this.ttHelp = new System.Windows.Forms.ToolTip(this.components);
            this.lblMeasure = new System.Windows.Forms.Label();
            this.lblTotalValue = new System.Windows.Forms.Label();
            this.label1 = new System.Windows.Forms.Label();
            this.SuspendLayout();
            // 
            // lblMeasure
            // 
            resources.ApplyResources(this.lblMeasure, "lblMeasure");
            this.lblMeasure.Name = "lblMeasure";
            // 
            // lblTotalValue
            // 
            this.lblTotalValue.BackColor = System.Drawing.Color.White;
            this.lblTotalValue.BorderStyle = System.Windows.Forms.BorderStyle.Fixed3D;
            resources.ApplyResources(this.lblTotalValue, "lblTotalValue");
            this.lblTotalValue.Name = "lblTotalValue";
            // 
            // label1
            // 
            resources.ApplyResources(this.label1, "label1");
            this.label1.Name = "label1";
            // 
            // DrawPathDialog
            // 
            resources.ApplyResources(this, "$this");
            this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
            this.Controls.Add(this.label1);
            this.Controls.Add(this.lblTotalValue);
            this.Controls.Add(this.lblMeasure);
            this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedSingle;
            this.MaximizeBox = false;
            this.MinimizeBox = false;
            this.Name = "DrawPathDialog";
            this.ShowIcon = false;
            this.TopMost = true;
            this.ResumeLayout(false);
            this.PerformLayout();

        }

        #endregion

        #region Constructors

        /// <summary>
        /// Creates a new instance of MeasureDialog
        /// </summary>
        public DrawPathDialog()
        {
            InitializeComponent();
            _measureMode = MeasureModes.Distance;
        }

        #endregion

        #region Methods

        #endregion

        #region Properties

        /// <summary>
        /// The total distance across all segments in meters
        /// </summary>
        public double TotalDistance
        {
            get { return _totalDistance; }
            set
            {
                _totalDistance = value;
                if (_measureMode == MeasureModes.Distance)
                {
                    double d = _totalDistance*_distFromMeters;
                    if(d < 1000)
                    {
                        lblTotalValue.Text = d + " ";
                    }
                    else
                    {
                        lblTotalValue.Text = (d).ToString("#,###") + " "; 
                    }
                    
                }
             
            }
        }


       

        #endregion

        #region Events

        #endregion

        #region Event Handlers

        #endregion

        #region Private Functions

        /// <summary>
        /// Clean up any resources being used.
        /// </summary>
        /// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
        protected override void Dispose(bool disposing)
        {
            if (disposing && (components != null))
            {
                components.Dispose();
            }
            base.Dispose(disposing);
        }
        
        /// <summary>
        /// Gets or sets whether to display the distances or areas.
        /// </summary>
        public MeasureModes MeasureMode
        {
            get { return _measureMode; }
            set
            {
                _measureMode = value;
                lblMeasure.Text = _measureMode == MeasureModes.Distance ? "Distance:" : "Area:";
            }
        }

        #endregion

        private void UpdateDistance(ToolStripMenuItem newItem, double fromMeters)
        {
            if (_currentDist == newItem) return;
            if(_currentDist != null)_currentDist.Checked = false;
            _currentDist = newItem;
            newItem.Checked = true;
            _distFromMeters = fromMeters;
        }

        private void toolStripButton2_Click(object sender, EventArgs e)
        {
            if(_measureMode != MeasureModes.Area)
            {
                MeasureMode = MeasureModes.Area;
                OnMeasureModeChanged();
                
            }
            
        }



        private void OnMeasureModeChanged()
        {
            if(MeasureModeChanged != null)MeasureModeChanged(this, new EventArgs());
        }

        private void toolStripButton1_Click(object sender, EventArgs e)
        {
            if(_measureMode != MeasureModes.Distance)
            {
               MeasureMode = MeasureModes.Distance;
                OnMeasureModeChanged();
            }
        }


       
    }
}